<?php

class ZFPainel_Grid extends Bvb_Grid
{
    
    public static $_loadDefaultTemplate = true;

    /**
     * Retorna o objeto Grid Table
     *
     * @param string $gridName Nome da grid
     * @param Zend_Config|array $options Opções da grid
     * @param string $id Id da Grid
     * @return ZFPainel_Grid_Deploy_Table
     */
    public static function myFactory($gridName, $options = array(), $id = '')
    {
        $grid = Bvb_Grid::factory('ZFPainel_Grid_Deploy_Table', $options, $id);
        $grid->setNameGrid($gridName);

        if (self::$_loadDefaultTemplate) {
            $grid->addTemplateDir(PATH_ZFEXTEND . '/ZFPainel/Grid/Template', 'ZFPainel_Grid_Template', 'table');
            $grid->setTemplate('Table', 'table');
        }

        $grid->addFormatterDir(PATH_ZFEXTEND . '/ZFPainel/Grid/Formatter', 'ZFPainel_Grid_Formatter');
        $grid->addFormatterDir(PATH_ZC . '/Painel/Grid/Formatter', 'ZC_Painel_Grid_Formatter');
        $grid->addFormatterDir(PATH_ZFEXTEND . '/ZFKiller/Grid/Formatter', 'ZFKiller_Grid_Formatter');

        $grid
                ->setAlwaysShowOrderArrows(false)
                ->setNoFilters(true)
                ->setExport(array())
                ->setRecordsPerPage(25)
                ->setImagesUrl(ZFDULCET_LIB_DIR_IMG . '/famfamfam/')
        ;

        return $grid;
    }
    
    /**
     * 
     * @param Zend_Db_Select $source
     * @return Bvb_Grid_Source_Zend_Select
     * @throws Exception
     */
    public static function factorySource($source)
    {
        if ($source instanceof Zend_Db_Select) {
            return new Bvb_Grid_Source_Zend_Select($source);
        }
        
        throw new Exception('Tipo de source indefinido');
    }
    
}
